package com.tsing.bms.controller;

import com.tsing.bms.service.IBuildingService;
import com.tsing.bms.vo.req.BuildingAddReqVo;
import com.tsing.bms.vo.req.BuildingUpdateReqVo;
import com.tsing.bms.vo.req.IdReqVo;
import com.tsing.bms.vo.req.IdsReqVo;
import com.tsing.bms.vo.resp.BuildingRespVo;
import com.tsing.common.annotations.SystemLog;
import com.tsing.common.utils.ResultUtil;
import com.tsing.common.vo.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
@Api(tags = "楼栋管理")
@RestController
@RequestMapping("/building")
public class BuildingController {

    @Autowired
    private IBuildingService buildingService;

    @PostMapping("/addBuilding")
    @ApiOperation(value = "新增楼栋")
    @SystemLog(description = "新增楼栋")
    public ResultData addBuilding(@Validated @RequestBody BuildingAddReqVo reqVo) {
        buildingService.addBuilding(reqVo);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteBuilding")
    @ApiOperation(value = "删除楼栋")
    @SystemLog(description = "删除楼栋")
    public ResultData deleteBuilding(@Validated @RequestBody IdsReqVo reqVo) {
        buildingService.deleteBuilding(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/getBuilding")
    @ApiOperation(value = "获取单个楼栋信息")
    @SystemLog(description = "获取单个楼栋信息")
    public ResultData<BuildingRespVo> getBuildingById(@Validated IdReqVo reqVo) {
        return ResultUtil.success(buildingService.getBuildingById(reqVo));
    }

    @PutMapping("/updateBuilding")
    @ApiOperation(value = "修改楼栋信息")
    @SystemLog(description = "修改楼栋信息")
    public ResultData updateBuilding(@Validated @RequestBody BuildingUpdateReqVo reqVo) {
        buildingService.updateBuilding(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/BuildingList")
    @ApiOperation(value = "楼栋列表")
    @SystemLog(description = "楼栋列表")
    public ResultData<List<BuildingRespVo>> BuildingList() {
        return ResultUtil.success(buildingService.BuildingList());
    }

}
